
function addOptionSM(oSelect,inValue)
{
   /* var opt=document.createElement("OPTION");
	opt.value=inValue;
	opt.text=inValue;
    oSelect.add(opt);*/
	var str = $("<option>"+inValue+"</option>");
	str.appendTo("#"+oSelect);
}
function alertmess(alertmessage){
	$.msgbox({
		    width:300,
		    height:120,
	        content:{type:'alert', content:alertmessage},
	        animation:0,//禁止拖拽
	        drag:false,//禁止动画
	        autoClose: 5 //自动关闭
	    });
		return false;
}
function confirmmess(alertmessage,inpath){
	$.msgbox({
		    width:300,
		    height:120,
	        content:{type:'confirm', content:alertmessage,url:inpath},
	        animation:0,//禁止拖拽
	        drag:false,//禁止动画
	        autoClose: 5 //自动关闭
	    });
		return false;
}
function addNumberSM(receiverType, formname,selectN) {
     var mobile=formname.mobile.value;
     var item = document.createElement("OPTION");
     var leng = $("#"+selectN +" option").length;
     //alert(mobile.length);
       if(mobile.length==0){
    	   alertmess('不能添加空联系人，请选择联系人！');
  		}else if(mobile.length<11){
			alertmess("您输入的手机号码无效！");
			
		}else{
			if (receiverType == 7)
			{
				/*for (i=0;i<leng;i++)
				{
					if ($("#"+selectN).options(i).value == formname.mobile.value)
					{
						alertmess("您选择的用户重复！");
					   return;
					}
				}*/
			}
			addOptionSM(selectN,mobile);
			formname.mobile.value="";
	  }
       
	}

	function delReceiverSM(formname,selectN)
	{
		$("#"+selectN+" option").each(function(){
			//alert("ddd"+$('#'+va+' option:selected').val());
			$('#'+selectN+' option:selected').remove();//delete the phone which selected
		});
	/*	var destItem;
		var item, itemValue;
		var i;
		srcItem = formname.selectN;
		alert("srcItem=="+formname.selectN.length);
		for (i=srcItem.length-1;i>=0;i--)
		{
			item = srcItem.item(i);
			if (item.selected)
			{
				itemValue = item.value.split("\4");
				item.value = itemValue[1];
				srcItem.remove(i);
			}
		}*/
	} 
	/**
	 *去除字符串内空格1
	 */
	function trims(inStr)
	{
	    return inStr.replace(/ /g,"");
	}//end function trims

	function insertallSM(formname){
	
	var isdingshi=formname.time;
    var thisradio;
     for(var i = 0; i< isdingshi.length; i++){
        if(isdingshi[i].checked){
        	thisradio=isdingshi[i].value;
        }

    }
    if(thisradio=="time"){
    	var sendTime=formname.sendTime.value;
    	
    	 var dt1=(sendTime);
    	 var d=new Date();
         var dt2=(d.getYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+d.getHours()+":"+(d.getMinutes()-1)+":"+d.getSeconds());
    		 
         var arrayD1=dt1.split(" ");
         var arrayD2=dt2.split(" ");
         dt1=new Date(arrayD1[0].split("-")[0],arrayD1[0].split("-")[1],arrayD1[0].split("-")[2],arrayD1[1].split(":")[0],arrayD1[1].split(":")[1],arrayD1[1].split(":")[2]);
         dt2=new Date(arrayD2[0].split("-")[0],arrayD2[0].split("-")[1],arrayD2[0].split("-")[2],arrayD2[1].split(":")[0],arrayD2[1].split(":")[1],arrayD2[1].split(":")[2]);
         var flag=(dt1>dt2);
    	 if(flag==false){
    		alertmess('您选择的时间不能小于当前时间，请重新发送！');
    		return false;
    	 }
    }
	var rec=formname.select1;
	
 
	//alert(rec);
	var len=rec.length;
	//alert(len);
	   if(rec.length>0){
	       for(var i=0;i<len;i++){
		       	if(rec.options[i].length<12)
		       	{
		       		alertmess("手机号码位数不对，请查证后重新输入！");
		       		return ;
		       	}
		         if(i==len-1){
		        	 formname.txtArea.value +=rec.options[i].text;
		         }else{
		        	 formname.txtArea.value +=rec.options[i].text+";";
		       }
	       }
	      // alert(formname.txtArea.value);
	       for(var i=0; i<rec.length; i++)
	       {
	    	   rec.options[i].selected="true"; 
	       }
	   	   formname.action="TbSmsServlet?method=save";
	       formname.submit();
		   }else{
		       formname.action="TbSmsServlet?method=save";
		       formname.submit();
		      
		   }
	   
	}
	  function giveNowTimeSM(formname)
	  {
		  var dt=new Date();
		  var tempMonth=parseInt(dt.getMonth()+1);
		  tempMonth=tempMonth<10?"0"+tempMonth:tempMonth;
		  var tempDay=parseInt(dt.getDate());
		  tempDay=tempDay<10?"0"+tempDay:tempDay;
		  var tempHours=parseInt(dt.getHours());
		  tempHours=tempHours<10?"0"+tempHours:tempHours;
		  var tempMinutes=parseInt(dt.getMinutes());
		  tempMinutes=tempMinutes<10?"0"+tempMinutes:tempMinutes;
		  var tempSeconds=parseInt(dt.getSeconds());
		  tempSeconds=tempSeconds<10?"0"+tempSeconds:tempSeconds;
		  var timeStr=dt.getYear()+'-'+tempMonth+'-'+tempDay+' '+tempHours+':'+tempMinutes+':'+tempSeconds;
		  formname.sendTime.value=timeStr;
	  }
	  function giveNowTimeMettingSM(formname)
	  {
		  var dt=new Date();
		  var tempMonth=parseInt(dt.getMonth()+1);
		  tempMonth=tempMonth<10?"0"+tempMonth:tempMonth;
		  var tempDay=parseInt(dt.getDate());
		  tempDay=tempDay<10?"0"+tempDay:tempDay;
		  var tempHours=parseInt(dt.getHours());
		  tempHours=tempHours<10?"0"+tempHours:tempHours;
		  var tempMinutes=parseInt(dt.getMinutes());
		  tempMinutes=tempMinutes<10?"0"+tempMinutes:tempMinutes;
		  var timeStr=dt.getYear()+'-'+tempMonth+'-'+tempDay+' '+tempHours+':'+tempMinutes;
		  formname.MettingTime.value=timeStr;
	  }
	 
function isReceveSM(formname,bl,inTrName)
{
    if(bl)
	{
	  giveNowTimeSM(formname);
	  document.getElementById(inTrName).style.display='none';
	}else{
	  document.getElementById(inTrName).style.display='block';
	}
}

//统计安监通知字数
function checkoverflowSM(formname,leng){
	var str = new String();
	str = formname.message.value;
	formname.counterMsg.value = leng - str.length;
	if (str.length>leng){
		formname.message.value = str.substr(0,leng);
		formname.counterMsg.value = 0;
		alertmess('您输入的信息的长度应不超过'+leng+'!');
		return false;
	}
	return true;
}
/*
 * 删除一个记录 
 */
function deleteOneSM(url){
	 var startTime = $("#startTime").val();
	 var endTime = $("#endTime").val();
	// alert('starttime:'+startTime+'endtime:'+endTime);
	 var content=$("#content").val();
	 var phone=$("#phone").val();
	 var inputurl = url+"&startTime="+startTime+"&endTime="+endTime+"&content="+content+"&phone="+phone;
	 
	//alert("url=="+url);
	 var lastUrl = encodeURI(inputurl);
		lastUrl = encodeURI(lastUrl);
	 confirmmess("你确定要删除此记录吗?",lastUrl);
		
	}
function shenheSM(url){
	 var startTime = $("#startTime").val();
	 var endTime = $("#endTime").val();
	 var content=$("#content").val();
	 var phone=$("#phone").val();
	// alert(url);
	 var inputurl = url+"&startTime="+startTime+"&endTime="+endTime+"&content="+content+"&phone="+phone;
	//alert("url=="+url);
	 var lastUrl = encodeURI(inputurl);
		lastUrl = encodeURI(lastUrl);
	 confirmmess("你确定要审核此记录吗?",lastUrl);
}
//多选删除
function deleteSmsAllSM(va,url)
{
	//alert("url="+url)
	var obj = document.getElementsByName(va);
	var idList = "";
	var num = 0;
	for(var i = 0;i<obj.length;i++)
	{
		if(obj[i].checked)
		{
			num++;
			idList+=obj[i].value+",";
		}
	}
	if(num<1)
	{
		alertmess("没有选择记录无法删除!");
		return ;
	}
	var lastUrl = encodeURI(url+"&idList="+idList);
	lastUrl = encodeURI(lastUrl);
	confirmmess('你确定删除吗?',lastUrl);
	
}


//全选功能
function check_allSM(va)
{
	var obj = document.getElementsByName(va);
	for(var o = 0;o<obj.length;o++)
	{
		if(obj[o].checked == true)
		{
			obj[o].checked = false;
		}else if(obj[o].checked == false)
		{
			obj[o].checked = true;
		}
	}
}
//根据条件进行查询
function searcherSM(inPath){
	//alert(inPath);
	var startTime = $("#startTime").val();
	 var endTime = $("#endTime").val();
	 var content=$("#content").val();
	 var phone=$("#phone").val();
	 var lastUrl = inPath+"&startTime="+startTime+"&endTime="+endTime+"&content="+content+"&phone="+phone;
	 var last_url = encodeURI(lastUrl);
	 last_url = encodeURI(last_url);
	 window.location=last_url;

}
//提交常用短语
function insertTemplateSM(formname,inPath){
	  var phraseContent=formname.message.value;
	  
	  var lastUrl=inPath+"&phraseContent="+phraseContent;
	  var last_url = encodeURI(lastUrl);
	  last_url = encodeURI(last_url);
	  if(phraseContent.length>0){
			confirmmess('您确定提交此常用短语吗?',last_url);
			//window.location=last_url;
		}else{
		  alertmess('常用短语内容不能为空!');
	  }
	
}
//常用短语选择
function checkformSM(inFormName,inTabIndex){
	var tempArray = document.getElementsByName("radioCommonPhrase");    
    var commonPhraseStr = '';     
    for(i=0;i<tempArray.length;i++)      
    {      
       if(tempArray[i].checked){   
    	   commonPhraseStr = tempArray[i].value;   
	   }   
    }   
    eval("top."+inFormName+".mb.rtVl=commonPhraseStr;");
    eval("top."+inFormName+".mb.close();");
}

//根据条件进行查询
function searcherByphone(inPath){
	 var phone=$("#phone").val();
	 var lastUrl = inPath+"&phone="+phone;
	 var last_url = encodeURI(lastUrl);
	 last_url = encodeURI(last_url);
	 window.location=last_url;

}

//根据条件进行查询
function searcherByDianbo(inPath){
	 var content=$("#content").val();
	 var dianbotype=$("#dianbotype").val();
	 var lastUrl = inPath+"&content="+content+"&dianbotype="+dianbotype;
	 var last_url = encodeURI(lastUrl);
	 last_url = encodeURI(last_url);
	 window.location=last_url;

}
